package com.example.project2;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class TextViewModel extends ViewModel {

    //声明LiveData对象
    private MutableLiveData<String> str;

    //无参构造函数，new一个新的对象，否则模拟器会闪退
    public TextViewModel() {
        this.str = new MutableLiveData<>();
    }

    //合并字符串函数
    public void union(String s1, String s2) {
        this.str.setValue(s1 + s2);
    }

    //返回结果函数
    public MutableLiveData<String> getStr() {
        return str;
    }
}
